package parts10.lesson156;

import java.util.ArrayList;
import java.util.DoubleSummaryStatistics;
import java.util.List;

/**
 *课时156 Stream数据流（MapReduce模型）
 */
public class Demo {
    public static void main(String[] args) {
        List<Order> all=new ArrayList<Order>();
        all.add(new Order("手机",1999.00,20));
        all.add(new Order("笔记本电脑",7999.00,50));
        all.add(new Order("JAVA开发",125.00,1000));
        all.add(new Order("铅笔",1.2,10000));

        double allPrice=all.stream().map((obj)->obj.getPrice()*obj.getAmount()).reduce((sum,x)->sum+x).get();
        System.out.println(allPrice);
        //换种统计方式
        //统计方法
        DoubleSummaryStatistics dss=all.stream().mapToDouble((obj)->obj.getPrice()*obj.getAmount()).summaryStatistics();
        System.out.println("sum:"+dss.getSum());
        System.out.println("average:"+dss.getAverage());
        System.out.println("max:"+dss.getMax());
        System.out.println("min:"+dss.getMin());
        System.out.println("count:"+dss.getCount());
    }
}
